package day02;

import java.util.Scanner;

/**
 * 要求用户输入一个字符串，然后若该字符串是一个整数，则转换为整数后输出乘以10后的结果
 * 若是小数，则转换为一个小数后输出乘以5后的结果，若不是数字则输出"不是数字"
 * 需要使用正则表达式进行判断。
 * @author Bonnie
 *
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.print("请输入数字:");
        Scanner scanner = new Scanner(System.in);
        String writeIn = scanner.next();
        String regex1 = "\\d+";
        String regex2 = "\\d+\\.\\d+";
        if (writeIn.matches(regex1)){
            int answer = Integer.parseInt(writeIn);
            System.out.println(answer * 10);
        }else if (writeIn.matches(regex2)){
            double answer = Double.parseDouble(writeIn);
            System.out.println(answer * 5);
        }else {
            System.out.println("不是数字");
        }
    }

}
